/***********************************************************************
 * Module:  CertificationController.java
 * Author:  Administrator
 * Purpose: Defines the Class CertificationController
 ***********************************************************************/

package ishitong.configManagement.controller;

import ishitong.commons.pagination.Pagination;
import ishitong.commons.pagination.PaginationResult;
import ishitong.vehicle.common.model.Certification;
import ishitong.vehicle.common.service.biz.CertificationService;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

/** @pdOid f688a43f-46d6-4f99-a502-c403930dfe9c */
@Controller
public class CertificationController extends ishitong.common.controller.ActionController {
   /** @pdOid 73c93f16-be16-4199-847f-13f9072c3213 */
   private static final String CER_SCH = "/configManagement/certification/certificationSearch";
   /** @pdOid 372fdc7f-5bb8-4ad5-84cd-db663c4243b8 */
   private static final String CER_SCH_LST = "/configManagement/certification/certificationSearchList";
   /** @pdOid 60c87d3f-6ccb-4af8-9b5f-3f2d5393fd70 */
   private static final String CER_EDT = "/configManagement/certification/certificationEdit";
   /** @pdOid 5f195e39-9dac-4bca-9835-d73322ae0284 */
   private static final String CER_VIW = "/configManagement/certification/certificationView";
   /** @pdOid d54efa2d-0982-4aff-beec-8b3fa64b4104 */
   private static final String CER_COM_VIW = "/configManagement/certification/certificationCommonView";
   /** @pdOid 21e4faf0-2b95-4861-ba3e-9aaefbbba824 */
   @Autowired
   private CertificationService certificationService;
   
   /** @param request
    * @exception Exception
    * @pdOid c7bb9d6c-a839-4c29-9851-1c94a1059678 */
   @RequestMapping(value = "/showCertificationSearch.do")
   public ModelAndView handleShowCertificationSearch(HttpServletRequest request) throws Exception {
   	return new ModelAndView(CER_SCH);
   }
   
   /** @param request 
    * @param certification 
    * @param pagination
    * @pdOid cd904a8f-7d2a-43f3-b5ee-07798fd2412c */
   @RequestMapping(value = "/ajaxCertificationSearchList.do", method = RequestMethod.POST)
   public ModelAndView handleAjaxFindCertificationSearchList(HttpServletRequest request, Certification certification, Pagination pagination) {
   	try {
   		Map<String, Object> model = new HashMap<>();
   		PaginationResult<Certification> page = certificationService.queryForPage(certification, pagination);
   		model.put("listCertification", page);
   		return new ModelAndView(CER_SCH_LST, model);
   	} catch (Exception e) {
   		e.printStackTrace();
   	}
   	return null;
   }
   
   /** @param request 
    * @param certificationId 
    * @param response
    * @exception Exception
    * @pdOid 99200f70-45db-4d60-87bf-04751400c6ba */
   @RequestMapping(value = "/ajaxShowCertificationEdit.do", method = RequestMethod.POST)
   public ModelAndView handleAjaxShowCertificationEdit(HttpServletRequest request, String certificationId, HttpServletResponse response) throws Exception {
   	try {
   		Certification certification = new Certification();
   		Map<String, Object> model = new HashMap<String, Object>();
   		if (!StringUtils.isEmpty(certificationId)) {
   			certification.setId(Long.valueOf(certificationId));
   			List<Certification> listCertification = certificationService.getCertificationByCondition(certification);
   			certification = listCertification.get(0);
   			model.put("certification", certification);
   		}
   		return new ModelAndView(CER_EDT, model);
   	} catch (Exception e) {
   		e.printStackTrace();
   	}
   	return null;
   }
   
   /** @param request 
    * @param certification 
    * @param response
    * @exception Exception
    * @pdOid 57df4d3d-c13f-43b8-9f44-a82b6568e418 */
   @RequestMapping(value = "/ajaxSaveCertification.do", method = RequestMethod.POST)
   public void handleAjaxSaveCertification(HttpServletRequest request, Certification certification, HttpServletResponse response) throws Exception {
   	try {
   		if (certification.getId() != null) {
   			certificationService.modifyCertification(certification);
   		} else {
   			certificationService.addCertification(certification);
   		}
   	} catch (Exception e) {
   		e.printStackTrace();
   	}
   }
   
   /** @param request 
    * @param certificationId
    * @exception Exception
    * @pdOid 76e85106-305d-415a-b3e9-54a8f8b48663 */
   @RequestMapping(value = "/ajaxShowCertificationView.do", method = RequestMethod.POST)
   public ModelAndView handleAjaxShowCertificationView(HttpServletRequest request, String certificationId) throws Exception {
   	try {
   		Certification certification = new Certification();
   		Map<String, Object> model = new HashMap<String, Object>();
   		if (!StringUtils.isEmpty(certificationId)) {
   			certification.setId(Long.valueOf(certificationId));
   			List<Certification> listCertification = certificationService.getCertificationByCondition(certification);
   			certification = listCertification.get(0);
   			model.put("certification", certification);
   		}
   		return new ModelAndView(CER_VIW, model);
   	} catch (Exception e) {
   		e.printStackTrace();
   	}
   	return null;
   }
   
   /** @param request 
    * @param certificationIds 
    * @param response
    * @exception Exception
    * @pdOid 6589dd9b-b582-4cb2-814b-931d95993773 */
   @RequestMapping(value = "/ajaxDeleteCertificationByIds.do", method = RequestMethod.POST)
   public void handleAjaxDeleteCertificationByIds(HttpServletRequest request, String certificationIds, HttpServletResponse response) throws Exception {
   	try {
   		certificationService.deleteCertificationById(Long.valueOf(certificationIds));
   	} catch (Exception e) {
   		e.printStackTrace();
   	}
   }
   
   /** @param request 
    * @param certification
    * @exception Exception
    * @pdOid ba1d752b-7ab0-4b3a-96bb-dc08194e2980 */
   @RequestMapping(value = "/ajaxFindCertificationCommon.do", method = RequestMethod.POST)
   public ModelAndView handleAjaxFindCertificationCommon(HttpServletRequest request, Certification certification) throws Exception {
   	try {
   		Map<String, Object> model = new HashMap<>();
   		if (!StringUtils.isEmpty(certification.getCertificatecode())) {
   			List<Certification> listCertification = certificationService.getCertificationByCondition(certification);
   			model.put("certification", listCertification.get(0));
   		}
   		List<Certification> lstCertification = certificationService.getCertificationByCondition(new Certification());
   		model.put("lstCertification", lstCertification);
   		return new ModelAndView(CER_COM_VIW, model);
   	} catch (Exception e) {
   		e.printStackTrace();
   	}
   	return null;
   }

}